import GameUtil from '../../Fantasy/Util/GameUtil';
import SoundUtil from '../../Fantasy/Util/SoundUtil';
import ServerCenter from '../../Server/ServerCenter';
import PromptManage from '../PromptManage';
// Learn TypeScript:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {


    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}
    @property(cc.Label)
    stamina:cc.Label = null;

    @property(cc.Label)
    exp:cc.Label = null;

    start() {

    }
    onEnable(){
        this.updateLabel();
    }
    updateLabel(){
        this.stamina.getComponent(cc.Label).string = ServerCenter.getUserStamina()+"";
        this.exp.getComponent(cc.Label).string = ServerCenter.getUserExp()+"";
    }



    btnCallback(target, data) {
        SoundUtil.playEffect("music/click");
        var str = "您当前经验值不足，请磨炼磨炼再来吧";
        if (data == 'close') {
            this.node.active = false;
        }
        else if (data == 'one') {
            GameUtil.currPkLevel= 1;
            let ste = ServerCenter.getUserStamina();
            if (ste >= 5){
                GameUtil.gotoScene('PKScene',null,true);
                ServerCenter.addUserStamina(-5);
            }
            else{
                PromptManage.addToast('您的体力值不够!')
            }
        }
        else if (data == 'two') {
            GameUtil.currPkLevel= 2;
            if(ServerCenter.getUserExp() < 1000){
                PromptManage.addToast(str)
            }else{
                let ste = ServerCenter.getUserStamina();
                if (ste >= 5){
                    GameUtil.gotoScene('PKScene',null,true);
                    ServerCenter.addUserStamina(-5);
                }
                else{
                    PromptManage.addToast('您的体力值不够!')
                }


            }
        }
        else if (data == 'three') {
            GameUtil.currPkLevel= 3;
            if(ServerCenter.getUserExp() < 3000){
                PromptManage.addToast(str)
            }else{
                let ste = ServerCenter.getUserStamina();
                if (ste >= 5){
                    GameUtil.gotoScene('PKScene',null,true);
                    ServerCenter.addUserStamina(-5);
                }
                else{
                    PromptManage.addToast('您的体力值不够!')
                }

            }
        }
        else if (data == 'four') {
            GameUtil.currPkLevel= 4;
            if(ServerCenter.getUserExp() < 5000){
                PromptManage.addToast(str)
            }else{
                let ste = ServerCenter.getUserStamina();
                if (ste >= 5){
                    GameUtil.gotoScene('PKScene',null,true);
                    ServerCenter.addUserStamina(-5);
                }
                else{
                    PromptManage.addToast('您的体力值不够!')
                }

            }
        }
    }
}
